import com.nextStep.dao.UserMapper;
import com.nextStep.entity.DbConfig;
import com.nextStep.entity.Users;
import com.nextStep.service.DbConfigService;
import com.nextStep.service.DbExecuteService;
import com.nextStep.service.UserService;
import javafx.application.Application;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class test {

    @Test
    public void test(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        DbExecuteService dbExecuteService = (DbExecuteService) context.getBean(DbExecuteService.class);
         List list = dbExecuteService.showTables(new DbConfig());
        for (Object o : list) {
            System.out.println((String) o);
        }
    }

    @Test
    public void testDBconfig(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        DbConfigService dbConfigService = context.getBean(DbConfigService.class);
        /*List list = dbConfigService.findConfig("123");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }*/
       /* DbConfig dbConfig= new DbConfig("22","22","22","22");
        int i = dbConfigService.addConfig(dbConfig);
        System.out.println(i);*/
       dbConfigService.delConfig("22");
    }

    @Test
    public void test2(){

        SqlSessionFactory factory = null;


            String fileName="mybatis-config.xml";
            try {
                InputStream inputStream= Resources.getResourceAsStream(fileName);
                factory = new SqlSessionFactoryBuilder().build(inputStream);
            }catch (IOException e){
                e.printStackTrace();
            }
        SqlSession session= factory.openSession();
        //获取当前类对象
        UserMapper userMapper = session.getMapper(UserMapper.class);
        //调用接口，自动执行xml中的sql
        //List<Users> userList = userMapper.queryUserAll();
        System.out.println();
        //for(Users user : userList){
        //    System.out.println(user);
        //}
       // session.close();

    }

    @Test
    public void threadTemp(){
        new Thread() {
            public void run() {
               for(int i = 0;i<=100;i++){
                   System.out.println("thread "+i);
               }
            }
        }.start();
        for(int i = 0;i<=100;i++){
            System.out.println("main "+i);
        }
    }

    @Test
    public void testString(){
        String veriCode = "{veriEnter:2222}";
        veriCode=veriCode.split(":")[1].replaceAll("\\}","");   //获得键值对中的值
        System.out.println(veriCode);
    }

    @Test
    public void testaaa(){
        System.out.println("select a ".substring(2));
    }
}
